home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Tools & Utilities
/
Collection of Tools and Utilities.iso
/
ada
/
gwuada_9.zip
/
READ.C
< prev
next >
Wrap
C/C++ Source or Header
|
1993-07-27
|
25KB
|
810 lines
/*
* Copyright (C) 1985-1992 New York University
*
* This file is part of the Ada/Ed-C system. See the Ada/Ed README file for
* warranty (none) and distribution info and also the GNU General Public
* License for more details.
*/
#define GEN
#include "hdr.h"
#include "libhdr.h"
#include "vars.h"
#include "segment.h"
#include "gvars.h"
#include "slot.h"
#include "ifile.h"
#include "axqrp.h"
#include "axqwp.h"
#include "libwp.h"
#include "gutilp.h"
#include "gmiscp.h"
#include "gmainp.h"
#include "libfp.h"
#include "librp.h"
#include "setp.h"
#include "libp.h"
#include "miscp.h"
#include "readp.h"
static void get_local_ref_maps(IFILE *, int);
static void put_local_ref_maps(IFILE *, int);
static void relocate_slots_a();
static void relocate_slots_b();
static void overwrite_stub_name(char *);
extern Segment CODE_SEGMENT, DATA_SEGMENT, DATA_SEGMENT_MAIN;
extern IFILE *AXQFILE, *LIBFILE, *AISFILE, *STUBFILE;
static Tuple code_slots_syms, data_slots_syms;
/* Input/Output of compiler files */
int load_unit(char *unit, int tree_is_needed) /*;load_unit*/
{
/*
* Retrieves the symbol table of the given unit and puts its information
* into the compilation maps.
* An AXQ may be read from the library if the unit has not yet been
* loaded. If the file cannot be opened, or the unit is not found, an
* error message is printed.
* BEWARE: the loaded AXQ may contain an unit with the same name as the
* current one, that must not be loaded, as its symbol table would
* override the current one.
*/
char *fname;
int file_retrieved;
Symbol unit_unam;
Tuple decmaps, decscopes, s_info;
Unitdecl ud;
fname = lib_unit_get(unit);
#ifdef TRACE
if (debug_flag) gen_trace(strjoin("load_unit ", unit));
#endif
if (fname == (char *)0) {
user_error(strjoin(formatted_name(unit), " not present in library"));
return FALSE;
}
else if (in_aisunits_read(unit)) {
file_retrieved = TRUE;
}
else {
file_retrieved =
(read_ais(fname, FALSE, unit, 0, tree_is_needed) != (char *)0);
if (is_subunit(unit)) read_stub(lib_unit_get(unit), unit, "st2");
#ifdef TBSL
if (is_subunit(unit)) {
/* If the subunit has been compiled, its stub environment
* overrides the one appearing in the axq of the parent unit.
*/
(for [n, env] in axqt) STUB_ENV(n) : = env;
end ;
}
else {
STUB_ENV +: = axqt;
}
#endif
}
if (file_retrieved && (ud = unit_decl_get(unit)) != (Unitdecl)0) {
/* [unit_unam, s_info, decls] = UNIT_DECL(unit); */
unit_unam = ud->ud_unam;
s_info = ud->ud_symbols;
decscopes = ud->ud_decscopes;
decmaps = ud->ud_decmaps;
/* TBSL does the info from decscopes and decmaps need to be restored
* or is the info restored by symtab_restore since declared info is
* stored with the symbols.
* DECLARED += decls;
* SYMBTABQ restore
*/
symtab_restore(s_info);
return TRUE;
}
else {
user_error(strjoin("Cannot retrieve unit ", formatted_name(unit)));
user_info(strjoin(" from file ", fname));
return FALSE;
}
}
void load_library(Axq axq) /*;load_library*/
{
/*
* retrieve information from LIBFILE
* Called only not newlib.
*/
int comp_status, si, i, j, n, m, unumber, nodes, symbols, cur_level;
int parent, unit_count;
Tuple stubtup, tup;
char *parent_name, *uname, *aisname, *tmp_str, *compdate;
Set precedes;
int n_code_slots, n_data_slots, n_exception_slots;
long cde_pos; /* offset for start of slot info */
IFILE *ifile;
ifile = LIBFILE;
/* library already opened */
unit_count = getnum(ifile, "lib-unit-count");
n = getnum(ifile, "lib-n");
empty_unit_slots = getnum(ifile, "lib-empty-slots");
tmp_str = getstr(ifile, "lib-tmp-str");
unit_number_expand(n);
for (i = 1; i <= unit_count; i++) {
struct unit *pUnit;
uname = getstr(ifile, "lib-unit-name");
unumber = getnum(ifile, "lib-unit-number");
aisname = getstr(ifile, "lib-ais-name");
compdate = getstr(ifile, "comp-date");
symbols = getnum(ifile, "lib-symbols");
nodes = getnum(ifile, "lib-nodes");
pUnit = pUnits[unumber];
pUnit->name = strjoin(uname, "");
pUnit->isMain = getnum(ifile, "lib-is-main");
pUnit->libInfo.fname = strjoin(aisname, "");
pUnit->libInfo.compDate = compdate;
comp_status = getnum(ifile, "lib-status");
pUnit->libInfo.obsolete = (comp_status) ? "ok" : "$D$";
pUnit->libUnit = (comp_status) ? strjoin(uname, "") : "$D$";
pUnit->aisInfo.numberSymbols = symbols;
pUnit->treInfo.nodeCount = nodes;
pUnit->treInfo.tableAllocated = (char *) tup_new(0);
}
n = getnum(ifile, "lib-n");
for (i = 1; i <= n; i++) {
uname = getstr(ifile, "lib-unit-name");
aisname = getstr(ifile, "lib-ais-name");
lib_stub_put(uname, aisname);
parent = getnum(ifile, "lib-parent");
if (parent == 0) parent_name = " ";
else parent_name = pUnits[parent]->name;
stub_parent_put(uname, parent_name);
cur_level = getnum(ifile, "lib-cur-level");
current_level_put(uname, cur_level);
si = stub_numbered(uname);
stubtup = (Tuple) stub_info[si];
m = getnum(ifile, "stub-file-size");
tup = tup_new(m);
for (j = 1; j <= m; j++)
tup[j] = (char *) getnum(ifile, "stub-files");
stubtup[4] = (char *) tup;
}
n = getnum(ifile, "precedes-map-size");
PRECEDES_MAP = tup_new(n);
for (i = 1; i <= n; i += 2) {
PRECEDES_MAP[i] = (char *) getnum(ifile, "precedes-map-ent");
m = getnum(ifile, "precedes-map-set-size");
precedes = set_new(m);
for (j = 1; j <= m; j++) {
precedes = set_with(precedes,
(char *) getnum(ifile, "precedes-map-ent"));
}
PRECEDES_MAP[i+1] = (char *) precedes;
}
n = getnum(ifile, "compilation_table_size");
compilation_table = tup_new(n);
for (i = 1; i <= n; i++)
compilation_table[i] = (char *) getnum(ifile, "compilation-table-ent");
/* late_instances */
n = getnum(ifile, "late-instances-size");
late_instances = tup_new(n);
for (i = 1; i <= n; i++)
late_instances[i] = getstr(ifile, "late-instances-str");
n = getnum(ifile, "interfaced-procedures-size");
interfaced_procedures = tup_new(n);
for (i = 1; i <= n; i += 2) {
interfaced_procedures[i] =
(char *) getnum(ifile, "interfaced-procedures-num");
interfaced_procedures[i+1]= getstr(ifile, "interfaced-procedures-str");
}
interface_counter = getnum(ifile, "interface-counter");
n = getnum(ifile, "units-size");
for (i = 1; i <= n; i++) {
pUnits[i]->libInfo.currCodeSeg =
(char *) getnum(ifile, "current-code-seg");
}
n = getnum(ifile, "units-size");
/* read local_reference_map for each unit (tuple of symbols and offsets) */
get_local_ref_maps(LIBFILE, n);
cde_pos = get_cde_slots(LIBFILE, axq);
/* Now set CODE_SLOTS, DATA_SLOTS and EXCEPTION_SLOTS from axq */
n_code_slots = axq->axq_code_slots_dim -1;
n_data_slots = axq->axq_data_slots_dim - 1;
n_exception_slots = axq->axq_exception_slots_dim - 1;
CODE_SLOTS = tup_new(n_code_slots);
for (i = 1; i <= n_code_slots; i++) {
CODE_SLOTS[i] = (char *) axq->axq_code_slots[i];
}
DATA_SLOTS = tup_new(n_data_slots);
for (i = 1; i <= n_data_slots; i++) {
DATA_SLOTS[i] = (char *) axq->axq_data_slots[i];
}
EXCEPTION_SLOTS = tup_new(n_exception_slots);
for (i = 1; i <= n_exception_slots; i++) {
EXCEPTION_SLOTS[i] = (char *) axq->axq_exception_slots[i];
}
/* could free axq_data_slots, etc., but keep for now */
/* read out LIB_STUB map (always empty for now) */
ifclose(LIBFILE);
return;
}
void store_axq(IFILE *file, int unit_num) /*;store_axq*/
{
/* Writes the AXQ file of compiled units (symmetrical to LOAD_AIS) */
int si, i, n, symbols, slots_ind, nsegs;
long begpos;
Tuple u_slots, symtup, tup;
Symbol sym;
Segment seg;
Fortup ft1;
Forset fs1;
char *uname;
Stubenv ev;
IFILE *ofile;
#ifdef TRACE
if (debug_flag) gen_trace_string("STORE_AXQ: ", pUnits[unit_num]->name);
#endif
/* In order to make the sequence of symbols written out dense (consecutive)
* without holes, the new symbols which are needed externally, namely
* GENERATED_OBJECTS have their seq numbers renumbed before being written
* out. This new ordering begins right after the sequence number of the last
* symbol read in from the semantic phase.
*/
pUnits[unit_num]->libInfo.compDate = (char *)greentime